﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SharedGenomics.Core;
using SharedGenomics.Workbench.Core;
using SharedGenomics.Workbench.PresentationModel;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public partial class AddSchemaView : View, IAddSchemaView
    {
        public AddSchemaView()
        {
            InitializeComponent();
        }

        [Region("OpenFile")]
        public Control OpenFileRegion
        {
            get { return this.plOpenFile; }
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            this.AddClicked.Raise(this);
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.CancelClicked.Raise(this);
        }

        #region IAddSchemaView Members

        public void ClearSelectedCategorialColumns()
        {
            this.lstCategorialColumns.ClearSelected();
        }

        public void ClearSelectedContinuousColumns()
        {
            this.lstContinuousColumns.ClearSelected();
        }

        public IEnumerable<FileSchemaColumnDTO> CategorialColumns
        {
            set { this.lstCategorialColumns.DataSource = value.ToList(); }
        }

        public IEnumerable<FileSchemaColumnDTO> ContinuousColumns
        {
            set { this.lstContinuousColumns.DataSource = value.ToList(); }
        }

        public FileSchemaColumnDTO SelectedCategorialColumn
        {
            get { return this.lstCategorialColumns.SelectedItem as FileSchemaColumnDTO; }
        }

        public FileSchemaColumnDTO SelectedContinuousColumn
        {
            get { return this.lstContinuousColumns.SelectedItem as FileSchemaColumnDTO; }
        }

        public FileSchemaColumnDTO DisplayedColumn
        {
            set
            {
                this.columnBindingSource.DataSource = value;
                this.lstValues.DataSource = value.Values;
                this.lstMissingValues.DataSource = value.MissingValues;
            }
        }

        public bool IsAddEnabled
        {
            set { this.btAdd.Enabled = value; }
        }

        public string SchemaName
        {
            get { return this.txtSchemaName.Text; }
        }

        public event EventHandler SelectedCategoricalColumnChanged;
        public event EventHandler SelectedContinuousColumnChanged;
        public event EventHandler AddClicked;
        public event EventHandler CancelClicked;

        #endregion

        private void lstCategoricalColumns_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SelectedCategoricalColumnChanged.Raise(this);
        }

        private void lstContinuousColumns_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SelectedContinuousColumnChanged.Raise(this);
        }
    }
}
